const DBUtil=require("../utils/DBUtil");
class Stu_infoService{
  //检测登陆
  checkLogin(s_id,s_pwd){
    return new Promise((resolve,reject)=>{
      var conn=DBUtil.getConn();
      conn.query("select * from stu_info where s_id=? and s_pwd=? and isDel=false ",[s_id,s_pwd],(err,result)=>{
        if(err){
          reject(err);
        }
        else{
          resolve(result);
        }
        conn.end();
      })
    })
  }

  //获取我的信息
  getMyInfo(s_id){
    return new Promise((resolve,reject)=>{
      var conn=DBUtil.getConn();
      conn.query("select * from stu_info where s_id=? and isDel=false ",[s_id],(err,result)=>{
        if(err){
          reject(err);
        }
        else{
          resolve(result);
        }
        conn.end();
      });
    });
  }
  
  /**
   * 
   * @param {*} s_id 
   * @param {*} s_photo 
   * @name 保存图片地址
   */
  uploadPhoto(s_id,s_photo){
    return new Promise((resolve,reject)=>{
      var conn=DBUtil.getConn();
      conn.query("update stu_info SET s_photo=? where s_id=?",[s_photo,s_id],(err,result)=>{
        if(err){
          reject(err);
        }
        else{
          if(result.affectedRows>0){
            resolve(true);
          }
          else{
            resolve(false);
          }
        }
        conn.end();
      });
    });
  }
  //根据学号查学生图片
  findPhotoByS_id(s_id){
    return new Promise((resolve,reject)=>{
      var conn=DBUtil.getConn();
      conn.query("select * from stu_info where s_id=?",[s_id],(err,result)=>{
        if(err){
          reject(err);
        }
        else{
          if(result.length>0){
            resolve(result[0].s_photo);
          }
          else{
            reject(null);
          }
        }
        conn.end();
      });
    })
  }
  //根据班级编号查询班级信息
  getStuListByC_id(c_id){
    return new Promise((resolve,reject)=>{
      var conn=DBUtil.getConn();
      conn.query("select * from stu_info where c_id=?",[c_id],(err,result)=>{
        if(err){
          reject(err);
        }
        else{
          resolve(result)
        }
        conn.end();
      });
    });
  }
}

module.exports=Stu_infoService;